# Copyright (c) SandboxAQ. All rights reserved.
# SPDX-License-Identifier: AGPL-3.0-only

load("//common/tools/proto2md:rules.bzl", "md_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
load("@rules_rust//proto/protobuf:defs.bzl", "rust_proto_library")

proto_library(
    name = "encoding_format_proto",
    srcs = ["encoding_format.proto"],
)

proto_library(
    name = "data_source_proto",
    srcs = ["data_source.proto"],
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":encoding_format_proto",
    ],
)

proto_library(
    name = "certificate_proto",
    srcs = ["certificate.proto"],
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":data_source_proto",
    ],
)

proto_library(
    name = "compliance_proto",
    srcs = ["compliance.proto"],
    visibility = [
        "//visibility:public",
    ],
)

proto_library(
    name = "private_key_proto",
    srcs = ["private_key.proto"],
    deps = [
        ":data_source_proto",
    ],
)

proto_library(
    name = "verifiers_proto",
    srcs = ["verifiers.proto"],
    deps = [
        ":certificate_proto",
    ],
)

proto_library(
    name = "tls_proto",
    srcs = ["tls.proto"],
    deps = [
        ":certificate_proto",
        ":compliance_proto",
        ":private_key_proto",
        ":verifiers_proto",
    ],
)

proto_library(
    name = "listener_configuration_proto",
    srcs = ["listener_configuration.proto"],
    visibility = [
        "//visibility:public",
    ],
)

proto_library(
    name = "tunnel_proto",
    srcs = ["tunnel.proto"],
    deps = [
        ":verifiers_proto",
    ],
)

proto_library(
    name = "api_proto",
    srcs = ["configuration.proto"],
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":listener_configuration_proto",
        ":tls_proto",
        ":tunnel_proto",
    ],
)

md_proto_library(
    name = "md_api_proto",
    package = "saq.sandwich.proto.api.v1",
    proto = ":api_proto",
    strip_package = True,
    symbols = [
        # configuration.proto
        "Implementation",
        "ClientOptions",
        "ServerOptions",
        "Configuration",

        # listener_configuration.proto
        "BlockingMode",
        "SocketAddress",
        "ListenerModeTCP",
        "ListenerConfiguration",

        # certificate.proto
        "Certificate",

        # private_key.proto
        "PrivateKey",

        # data_source.proto
        "DataSource",
        "ASN1DataSource",

        # encoding_format.proto
        "ASN1EncodingFormat",

        # compliance.proto
        "ClassicalAlgoChoice",
        "QuantumSafeAlgoChoice",
        "HybridAlgoChoice",
        "NISTSecurityStrengthBits",
        "Compliance",

        # tls.proto
        "X509Identity",
        "TLSOptions",
        "TLSClientOptions",
        "TLSServerOptions",
        "TLSv12Config",
        "TLSv13Config",

        # tunnel.proto
        "TunnelConfiguration",

        # verifiers.proto
        "EmptyVerifier",
        "X509Verifier",
        "SANMatcher",
        "SANVerifier",
        "TunnelVerifier",
    ],
    visibility = [
        "//visibility:public",
    ],
)

##################
# Python library #
##################

py_proto_library(
    name = "encoding_format_python_proto",
    srcs = [
        "encoding_format.proto",
    ],
    visibility = ["//:__subpackages__"],
)

py_proto_library(
    name = "data_source_python_proto",
    srcs = [
        "data_source.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":encoding_format_python_proto",
    ],
)

py_proto_library(
    name = "certificate_python_proto",
    srcs = [
        "certificate.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":data_source_python_proto",
    ],
)

py_proto_library(
    name = "compliance_python_proto",
    srcs = [
        "compliance.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":data_source_python_proto",
    ],
)

py_proto_library(
    name = "listener_configuration_python_proto",
    srcs = [
        "listener_configuration.proto",
    ],
    visibility = ["//visibility:public"],
)

py_proto_library(
    name = "private_key_python_proto",
    srcs = [
        "private_key.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":data_source_python_proto",
    ],
)

py_proto_library(
    name = "verifiers_python_proto",
    srcs = [
        "verifiers.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":certificate_python_proto",
    ],
)

py_proto_library(
    name = "tls_python_proto",
    srcs = [
        "tls.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":certificate_python_proto",
        ":compliance_python_proto",
        ":private_key_python_proto",
        ":verifiers_python_proto",
    ],
)

py_proto_library(
    name = "tunnel_python_proto",
    srcs = [
        "tunnel.proto",
    ],
    visibility = ["//:__subpackages__"],
    deps = [
        ":verifiers_python_proto",
    ],
)

py_proto_library(
    name = "api_python_proto",
    srcs = ["configuration.proto"],
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":tls_python_proto",
        ":tunnel_python_proto",
    ],
)

##############
# Go library #
##############

go_proto_library(
    name = "api_go_proto",
    importpath = "github.com/sandbox-quantum/sandwich/go/proto/sandwich/api/v1",
    protos = [
        ":api_proto",
        ":certificate_proto",
        ":compliance_proto",
        ":data_source_proto",
        ":encoding_format_proto",
        ":listener_configuration_proto",
        ":private_key_proto",
        ":tls_proto",
        ":tunnel_proto",
        ":verifiers_proto",
    ],
    visibility = [
        "//visibility:public",
    ],
)

################
# Rust library #
################

rust_proto_library(
    name = "api_rust_proto",
    crate_name = "sandwich_api_proto",
    rustc_flags = [
        "-A",
        "ambiguous-glob-reexports",
    ],
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":api_proto",
    ],
)

###############
# C++ library #
###############

cc_proto_library(
    name = "api_cc_proto",
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":api_proto",
    ],
)
